package Euler62;

import java.util.*;
import ReusableCode.*;

public class CubicPermutations {
	public static void main(String[] args) {
		long max = 10000;
		int permNum = 0;
		long perm = 0;
		HashMap<Integer, List<Long>> cubes = new HashMap<Integer, List<Long>>();
		
		System.out.println("Working...");
		
		//Create the default hash table.
		for(int i = 0; i < 15; i++)
		{
			cubes.put(i, new ArrayList<Long>());
		}
			
		//Create the cubes.
		for(int i = 1; i < max; i++)
		{
			long cube = (long) i * i * i;
			int diglen = MathFunctions.numberOfDigits(cube);
			List<Long> hash = cubes.get(diglen);
			
			hash.add(cube);
			cubes.put(diglen, hash);
		}
		
		//Find Permutations.
		for(int i = 1; i < max; i++)
		{
			long cube = (long) i * i * i;
			int digs[] = MathFunctions.getDigits(cube);
			List<Long> hash = cubes.get(digs.length);
			int count = 0;
			
			for(Iterator<Long> iter = hash.iterator(); iter.hasNext();)
			{
				long num = iter.next();
					
				if(GeneralFunctions.isPermutation(cube, num))
				{
					count++;
				}
			}
			
			if(count == 5)
			{
				permNum = count;
				perm = cube;
				break;
			}
		}
		
		System.out.println(perm);
		System.out.println(permNum);
	}
}
